<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('课题金额审批')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-apply-edit" th:object="${sciHorizontalApply}">
        <input name="urlFlag" id="urlFlag" th:field="*{urlFlag}"  type="hidden">
        <input name="state" id="state" th:field="*{state}" type="hidden">
        <input name="id" id="ktid" th:field="*{id}" type="hidden">
        <input name="reid" id="reid" th:field="*{reid}" type="hidden">
        <input name="amount" id="amount" th:field="*{amount}" type="hidden">
        <input  id="amountType" name="reAmount" type="hidden" th:field="*{amountType}"></input>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">申请人：</label>
                    <div class="col-sm-8">
                        <input  readonly th:field="*{userName}" class="form-control" type="text" >
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题编号：</label>
                    <div class="col-sm-8">
                        <input  readonly th:field="*{topNumber}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题类型：</label>
                    <div class="col-sm-8">

                        <select  readonly class="form-control" th:with="type=${@dict.getType('sci_top_type')}" required disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{topType}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题名称：</label>
                    <div class="col-sm-8">
                        <input  readonly th:field="*{topName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目金额：</label>
                    <div class="col-sm-8">
                        <input readonly th:field="*{amount}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">申请日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="signingData" autocomplete="off" th:field="*{signingData}" th:value="${#dates.format(signingData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required disabled>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">到账金额：</label>
                    <div class="col-sm-8">
                        <input readonly id="reamount" th:field="*{reAmount}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">到账日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="accountData" autocomplete="off" th:field="*{accountData}" th:value="${#dates.format(signingData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required disabled>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">主持人：</label>
                    <div class="col-sm-8">

                        <!--                        <input name="firstPersonId" th:field="*{firstPersonId}" class="form-control" type="text" required>-->
                        <select name="firstPersonId" class="form-control m-b" disabled>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.firstPersonId}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员1：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="secondPersonTask" th:field="*{secondPersonTask}" class="form-control" type="text" required>-->
                        <select name="secondPersonId" class="form-control m-b" disabled >
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.secondPersonId}" ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员2：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="thirdPersonId" th:field="*{thirdPersonId}" class="form-control" type="text" required>-->
                        <select  class="form-control m-b" disabled>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.thirdPersonId}"  ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员3：</label>
                    <div class="col-sm-8">
                        <select  class="form-control m-b" disabled>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.fourthPersonId}"  ></option>
                        </select>
                    </div>
                </div>
            </div>
            <!-- 其他成员（第5位及以后）：只读展示 -->
            <div class="col-xs-12" th:if="${extraMembers != null}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">其他成员：</label>
                    <div class="col-sm-10">
                        <div id="memberContainer" class="row">
                            <div class="col-xs-3 m-b-xs" th:each="mid : ${extraMembers}">
                                <select class="form-control m-b" disabled>
                                    <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == mid }"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">佐证材料：</label>
                    <div class="col-sm-8">
                        <input th:field="*{reamountUrl}" hidden id="reamountUrl" type="text" >
                        <div style="display: inline-block;">
                            <div id="reamountUrlFileName" style="display: inline; margin-right: 5px;"></div>
                        </div>
                        <div>
                            <button onclick="chakan()" class="btn btn-sm btn-primary color">预览</button>
                            <button onclick="downloadFile('reamountUrl')" class="btn btn-sm btn-primary color">下载</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4 tdiv1" style="display:none;"> 批阅记录</h4>
        <div class="row tdiv1" style="display:none;">
            <div class="col-sm-12">
                <div class="form-group"  >
                    <label class="col-xs-2 control-label">批注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" required maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>

            </div>
        </div>
        <h4 class="form-header h4 tdiv2"  style="display:none;">批阅记录</h4>
        <div class="row tdiv2" style="display:none;">
            <div class="col-sm-12">

                <div class="form-group"  >
                    <table id='bootstrap-table'></table>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" id="btn1" style="display:none;" class="btn btn-sm btn-primary" onclick="submitHandler()">  通 过</button>&nbsp;
        <button type="button" id="btn2" style="display:none;" class="btn btn-sm btn-danger" onclick="submitHandlerBH()"> 驳回/重新上传</button>
        <button type="button" id="btn3" style="display:none;" class="btn btn-sm btn-warning" onclick="closeItem()"> 关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
    function displayFileName(inputId, fileNameId) {
        const input = document.getElementById(inputId);
        const fileNameSpan = document.getElementById(fileNameId);
        if (input.value) {
            const fileName = input.value.split('/').pop(); // 获取最后一个'/'后的文件名
            fileNameSpan.textContent = fileName; // 直接显示完整文件名
        } else {
            fileNameSpan.textContent = '无效文件';
        }
    }
    function chakan(){
        var relativePath = $("#reamountUrl").val();
        if (!relativePath) {
            alert("没有可预览的文件！");
            return;
        }
        // 获取当前页面的上下文路径
        var contextPath = '/' + window.location.pathname.split('/')[1];
        // 拼接完整 URL
        var fullPath = window.location.origin + contextPath + relativePath;
        // 打开新窗口预览
        window.open(fullPath, '_blank');
    }

    function downloadFile(type){
        var contextPath = '/' + window.location.pathname.split('/')[1];
        var c = window.location.origin + contextPath + $("#"+type).val();
        if(c){
            var a = document.createElement("a");
            a.href=c;
            a.download="";
            a.style.display = "none";
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
        }else{
            alert("网址无效");
        }

    }
    $(function(){
        var kid = $("#ktid").val();
        var options = {
            url: prefix + "/abhyy/"+kid,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination:false,
            sortName: "createTime",
            sortOrder: "desc",
            columns: [

                {
                    field : 'createTime',
                    title : '批阅时间',
                    width: 200

                } ,
                {
                    field : 'uname',
                    title : '批阅人',
                    width: 100
                },
                {
                    field : 'concate',
                    title : '内容',
                    width: 500
                },
                {
                    field : 'state',
                    title : '审核状态',
                    width: 100
                } ]
        };

        $.table.init(options);

        $('#bootstrap-table').on('load-success.bs.table', function (e, name, args) {
            console.log('Event Name:', name.rows);

            var a =$("#state").val();
            if ($("#urlFlag").val() == 'chakan'){
                $("#btn3").show();
                $(".tdiv2").show()
            }else {
                if(a == 2 ||a == 1 || a == 11){
                    if(name.rows.length > 0){
                        $(".tdiv2").show();
                    }
                    $(".tdiv1").show();
                    $("#btn1").show();
                    $("#btn2").show();
                    $("#btn3").show();
                }
            }


        });




        <!-- laydate示例 -->
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#laydate-demo-4',
                range: true
            });
            var startDate = laydate.render({
                elem: '#laydate-startTime',
                max: $('#laydate-endTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 结束时间大于开始时间
                    if (value !== '') {
                        endDate.config.min.year = date.year;
                        endDate.config.min.month = date.month - 1;
                        endDate.config.min.date = date.date;
                    } else {
                        endDate.config.min.year = '';
                        endDate.config.min.month = '';
                        endDate.config.min.date = '';
                    }
                }
            });
            var endDate = laydate.render({
                elem: '#laydate-endTime',
                min: $('#laydate-startTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 开始时间小于结束时间
                    if (value !== '') {
                        startDate.config.max.year = date.year;
                        startDate.config.max.month = date.month - 1;
                        startDate.config.max.date = date.date;
                    } else {
                        startDate.config.max.year = '';
                        startDate.config.max.month = '';
                        startDate.config.max.date = '';
                    }
                }
            });
        });
    });
</script>
<script th:inline="javascript">
    var prefix = ctx + "system/apply";
    $("#form-apply-edit").validate({
        focusCleanup: true
    });



    function submitHandler() {
        var a = parseFloat($("#amount").val());
        var b = parseFloat($("#reamount").val());
        if(a!==0){
            var c = (b/(a * 0.7)).toFixed(1);
        }else {
            $modal.alertError("错误，请联系管理员");
            $("#btn3").click();
        }
        $.operate.saveTab(prefix + "/amountPass", {"id":$("#ktid").val(),"reid":$("#reid").val(),"urlFlag":$("#urlFlag").val(),"amount":$("#amount").val(),"scale":c,"amountType":$("#amountType").val()});

    }
    function submitHandlerBH() {
        var a = $("#urlFlag").val();
        if ($.validate.form()) {
            $.operate.saveTab(prefix + "/amountBh",   $('#form-apply-edit').serialize());
        }
    }

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        $(this).fileinput({
            'uploadUrl': ctx + 'common/upload/hxkt',
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
        maxFileSize: 51200,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(this).fileinput('_initFileActions');
    });
    // 页面加载时显示文件名
    window.onload = function() {
        displayFileName('reamountUrl', 'reamountUrlFileName');
    };
</script>
</body>
</html><!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('课题批阅')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
</html>